<template>
  <div>
    <h2 :class="{ title: true }">欢迎光临Vue开发的收银系统之水果店</h2>
    <table border="1">
      <thead>
        <tr>
          <th>火龙果 {{ costPrice }}￥/斤，折扣 &lt;{{ discount }}折&gt;</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>
            请输入你要购买的斤数 <input type="text" v-model.number="count" />
          </td>
        </tr>
        <tr>
          <td><button @click="pay">买完了，结账!</button></td>
        </tr>
        <tr>
          <td>
            结账单:&nbsp;<span>总价:{{ totalPrice ? totalPrice : 0 }}￥元</span
            >&nbsp;
            <span>折后价:{{ discountPrice ? discountPrice : 0 }}￥元</span
            >&nbsp;
            <span>省了:{{ totalPrice - discountPrice }}￥元</span>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      costPrice: 15, //原价
      discount: 6, //折扣
      count: "", //斤数
      totalPrice: "", //总价
      discountPrice: "", //折扣价
    };
  },
  methods: {
    pay() {
      this.totalPrice = this.count * this.costPrice;
      this.discountPrice = this.count * (this.costPrice * (this.discount / 10));
    },
  },
};
</script>

<style scoped lang="less">
.title {
  text-align: center;
}
table {
  margin: 0 auto;
  width: 500px;
  border: 2px solid skyblue;
  tr {
    height: 30px;
    border: 2px solid skyblue;
    text-align: center;
    span {
      font: 16px 楷体;
    }
  }
}
</style>
